package org.dyk.seamanshousefrontdesk.config;

import org.dyk.seamanshousefrontdesk.model.User;
import org.dyk.seamanshousefrontdesk.tools.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User userData = (User) request.getSession().getAttribute(Constants.USER_SESSION);
        if (null != userData){
            return true;
        }else {
            System.out.println("====拦截器运行===");
            System.out.println("未登录，跳转到登陆界面");
            response.sendRedirect(request.getContextPath() + "/login");
            return false;
        }
    }
}
